﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace MINERP.DAL.Statistics
{
    public class ProductStatDAL:DALBase
    {
        public static DataSet GetProductStat(int shopId, DateTime startTime,DateTime endTime)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("GetProductStat");
            db.AddInParameter(dbCommand, "@shopId", DbType.Int32, shopId);
            db.AddInParameter(dbCommand, "@startTime", DbType.DateTime, startTime);
            db.AddInParameter(dbCommand, "@endTime", DbType.DateTime, endTime);
            return db.ExecuteDataSet(dbCommand);
        }

        public static List<Tb_PorductCategory> GetAllCategory()
        {
            return DataEntites.Tb_PorductCategory.ToList();
        }


        //根据分类的名称得到该分类的产品列表
        public static List<string> GetProductByCategroyName(string categoryName)
        {
           return  DataEntites.Tb_Product.Where(tp => tp.Tb_PorductCategory.ProductCategoryName == categoryName).Select(p => p.ProductName).Distinct().ToList();
        }


        public static DataSet GetFactoryProductS(string categoryName, string ProductName,DateTime startTime,DateTime endTime)
        {
            Database db = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = db.GetStoredProcCommand("GetProducts");
            dbCommand.CommandTimeout = 600;
            db.AddInParameter(dbCommand, "@categoryName", DbType.String, categoryName);
            db.AddInParameter(dbCommand, "@ProductName", DbType.String, ProductName);
            db.AddInParameter(dbCommand, "@startTime", DbType.Time, startTime);
            db.AddInParameter(dbCommand, "@endTime", DbType.Time, endTime);

            return db.ExecuteDataSet(dbCommand);
        }
        public static DataSet GetProductCount(DateTime inStartTim,DateTime  inEndTime)
        {
            Database db = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = db.GetStoredProcCommand("Proce_ProductCount");
            dbCommand.CommandTimeout = 600;
            db.AddInParameter(dbCommand, "@startTime", DbType.DateTime, inStartTim);
            db.AddInParameter(dbCommand, "@endTime", DbType.DateTime, inEndTime);
            return db.ExecuteDataSet(dbCommand);
        }
    }
}
